﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DXApplicationTangche.UC.生产计划.编排生产批.service;

namespace DXApplicationTangche.UC.生产计划.编排生产批
{
    public partial class Form拆批 : DevExpress.XtraEditors.XtraForm
    {
        private String batchNo;
        private String batchQuantiry;
        public List<DTO生产批> List拆批 = new List<DTO生产批>();
        public Form拆批(String batchNo,String batchQuantiry)
        {
            InitializeComponent();
            this.batchNo = batchNo;
            this.batchQuantiry = batchQuantiry;
        }

        private void simpleButton拆批_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.textBox拆分批次.Text))
            {
                MessageBox.Show("拆分批次錯誤");
                return;
            }
            if (Convert.ToDouble(this.textBox拆分批次.Text)>= Convert.ToDouble(this.batchQuantiry))
            {
                MessageBox.Show("拆分批次錯誤");
                return;
            }
            try
            {
                this.List拆批 = 编排生产批Service.post拆批(this.batchNo,Convert.ToDouble(this.textBox拆分批次.Text));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            this.Close();
        }

        private void textBox拆分批次_KeyPress(object sender, KeyPressEventArgs e)
        {
            //允许输入数字、小数点、删除键和负号  
            if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.'))
            {
                //MessageBox.Show("请输入正确的数字");
                this.textBox拆分批次.Text = "";
                e.Handled = true;
            }
            if (e.KeyChar == (char)('-'))
            {
                if (textBox拆分批次.Text != "")
                {
                    //MessageBox.Show("请输入正确的数字");
                    this.textBox拆分批次.Text = "";
                    e.Handled = true;
                }
            }
            //小数点只能输入一次  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text.IndexOf('.') != -1)
            {
                //MessageBox.Show("请输入正确的数字");
                this.textBox拆分批次.Text = "";
                e.Handled = true;
            }
            //第一位不能为小数点  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text == "")
            {
                //MessageBox.Show("请输入正确的数字");
                this.textBox拆分批次.Text = "";
                e.Handled = true;
            }
            //第一位是0，第二位必须为小数点  
            if (e.KeyChar != (char)('.') && ((TextBox)sender).Text == "0")
            {
                //MessageBox.Show("请输入正确的数字");
                this.textBox拆分批次.Text = "";
                e.Handled = true;
            }
            //第一位是负号，第二位不能为小数点  
            if (((TextBox)sender).Text == "-" && e.KeyChar == (char)('.'))
            {
                //MessageBox.Show("请输入正确的数字");
                this.textBox拆分批次.Text = "";
                e.Handled = true;
            }
        }
    }
}